package com.wangyk.user.controller;

import com.wangyk.rabbitmqcommon.VO.ResultVO;
import com.wangyk.rabbitmqcommon.model.user.UserInfo;
import com.wangyk.rabbitmqcommon.utils.ResultVOUtils;
import com.wangyk.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("/user")
@Slf4j
public class UserController
{
    @Autowired
    private UserService userService;

    /**
     * 添加一位用户
     */
    @RequestMapping("/add_user.do")
    @ResponseBody
    public ResultVO addUser()
    {
        UserInfo userInfo=new UserInfo();
        userInfo.setUsername("王二（买家）");
        userInfo.setCreate_time(new Date());
        userInfo.setOpenid("oH99Av4N0pOXS0V7UN6kDCA2mZqE");
        userInfo.setPassword("wanger");
        userInfo.setRole((byte)1);
        userInfo.setUpdate_time(new Date());
        ResultVO resultVO = userService.addUser(userInfo);
        log.debug(userInfo.getId());
        return ResultVOUtils.success(resultVO);
    }

    /**
     * 查询一位用户
     */
    @RequestMapping("/find_by_openid.do")
    @ResponseBody
    public ResultVO findByOpenid(@RequestParam("openId") String openId)
    {
        ResultVO resultVO = userService.findByOpenid(openId);
        return ResultVOUtils.success(resultVO);
    }

    /**
     * like查询所有用户
     */
    @RequestMapping("/find_like_openid.do")
    @ResponseBody
    public ResultVO findLikeOpenid(@RequestParam("openId") String openId)
    {
        log.info("controller openId:"+openId);
        ResultVO resultVO = userService.findLikeOpenid(openId);
        return ResultVOUtils.success(resultVO);
    }
}
